package com.zhs.smartmall.coupon.service.impl;


import com.zhs.smartmall.coupon.model.SmsSpuBounds;
import com.zhs.smartmall.coupon.dao.SmsSpuBoundsDao;
import com.zhs.smartmall.coupon.service.ISmsSpuBoundsService;
import com.zhs.smartmall.coupon.dto.SmsSpuBoundsDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class SmsSpuBoundsServiceImpl extends ServiceImpl< SmsSpuBoundsDao, SmsSpuBounds> implements ISmsSpuBoundsService {

    @Resource
    private SmsSpuBoundsDao smsSpuBoundsDao;

    @Override
    @Transactional
    public R addOrUpdate(SmsSpuBoundsDto smsSpuBoundsDto) {
        if (BeanUtil.isEmpty(smsSpuBoundsDto)) throw new ServiceException("数据不能为空");
        SmsSpuBounds smsSpuBounds = new SmsSpuBounds();
        BeanUtil.copyProperties(smsSpuBoundsDto,smsSpuBounds);
        if (smsSpuBoundsDto.getId() == null){
            smsSpuBoundsDao.insert(smsSpuBounds);
            return R.ok("数据插入成功");
        }else {
            smsSpuBoundsDao.updateById(smsSpuBounds);
            return R.ok("数据更新成功");
        }
    }
}